#!/bin/bash

cd $(dirname $0)

source ./env.sh

images=(
    prom/prometheus:latest
    prom/alertmanager:latest
    prom/node-exporter:latest
    grafana/grafana:latest
    stefanprodan/caddy:latest
    google/cadvisor:latest
)

function replace (){
    image=$1
    harbor_project=$2
    if [ "$(echo $image | grep /)" ]; then
        name_tag=$(echo $image | awk -F '/' '{print $2}')
    else
        name_tag=$image
    fi

    echo "---------- $(echo $name_tag | awk -F ':' '{print $1}') ----------"

    docker pull $image
    docker tag $image ${harbor_project}/${name_tag}
    docker push ${harbor_project}/${name_tag}
    docker rmi $image
}


for image in ${images[@]}; do
    replace $image ${HARBOR_PROJECT}
done